import { GameData } from "../Data/GameData";
import GameStorage from "../Data/GameStorage";
import AssetsManager from "../Manager/AssetsManager";
import MainPanel from "../UI/MainPanel";

const { ccclass, property, executionOrder } = cc._decorator;

@ccclass
// 慢一点执行
@executionOrder(101)
export default class MainScene extends cc.Component {
    static Instance: MainScene;

    async onLoad() {
        MainScene.Instance = this;

        {
            // 获取碰撞检测系统：
            let manager = cc.director.getCollisionManager();
            // 默认碰撞检测系统是禁用的，如果需要使用则需要以下方法开启碰撞检测系统：
            manager.enabled = true;
            // 默认碰撞检测系统的 debug 绘制是禁用的，如果需要使用则需要以下方法开启 debug 绘制：
            // manager.enabledDebugDraw = true;
        }

        // console.log(`Main-onLoad------------`);

        // console.log(`isFirstEnter`, GameData.isFirstEnterMainScene);

        if (GameData.isFirstEnterMainScene) {
            GameData.isFirstEnterMainScene = false;

            GameStorage.initData();

            // GameData.InitData();

            await AssetsManager.Load_All();
        }

        MainPanel.Instance.ShowOn();
    }

    start() {
        // console.log(`Main-start------------`);
    }

    ShowOn() {
        GameStorage.initData();

        this.node.active = true;
        this.AddListener();

    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }

    AddListener() {
    }

    RemoveListener() {
    }

    private on_Button_startGame() {
        this.EnterGame();
    }

    EnterGame() {
        cc.director.loadScene("GameScene");
    }

}